package com.quanyan.riding.service.impl;

import com.quanyan.riding.entity.db.TbRunRideLevel;
import com.quanyan.riding.entity.db.TbRunRideLevelExample;
import com.quanyan.riding.mapper.TbRideLevelMapper;
import com.quanyan.riding.service.RidingPublicService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author xian-guo
 * @email 498152332@qq.com
 * @date 2016/8/29.
 */
@Service("ridingPublicServiceImpl")
public class RidingPublicServiceImpl implements RidingPublicService {

    private static final Logger LOGGER = LoggerFactory.getLogger(RidingPublicServiceImpl.class);

    /**
     * 等级表
     */
    @Autowired
    private TbRideLevelMapper tbRunRideLevelMapper;

    /**
     * 查询某个类型的全部等级信息
     * @param type  跑步-->1 or 骑行-->2
     * @return
     */
    @Override
    public List<TbRunRideLevel> getRunRideLevel(Byte type) {
        LOGGER.debug("跑步1 or  骑行2------->"+type);
        TbRunRideLevelExample tbRunRideLevelExample=new TbRunRideLevelExample();
        tbRunRideLevelExample.createCriteria().andTypeEqualTo(type);
        return tbRunRideLevelMapper.selectByExample(tbRunRideLevelExample);
    }

    /**
     *查询某个类型中某个等级的信息
     * @param type  类型
     * @param level  等级
     * @return
     */
    @Override
    public TbRunRideLevel getOneRunRideLevel(Byte type, Byte level) {
        TbRunRideLevelExample tbRunRideLevelExample=new TbRunRideLevelExample();
        tbRunRideLevelExample.createCriteria().andTypeEqualTo(type).andLevelEqualTo(level);
        List<TbRunRideLevel> tbRunRideLevelList=tbRunRideLevelMapper.selectByExample(tbRunRideLevelExample);
        return tbRunRideLevelList.size()>0?tbRunRideLevelList.get(0):null;
    }
}
